package com.fanshe.demo05;

import java.lang.reflect.Method;

public class Demo01 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException {
        //method01();
        //method02();
        //method03();
        method04();
        //method05();
    }

    private static void method05() throws ClassNotFoundException, NoSuchMethodException {
        Class aClass = Class.forName("com.fanshe.demo05.Student");
        Method declaredMethod = aClass.getDeclaredMethod("show");
        System.out.println(declaredMethod);
    }

    private static void method04() throws ClassNotFoundException, NoSuchMethodException {
        Class aClass = Class.forName("com.fanshe.demo05.Student");
        Method function2 = aClass.getMethod("function2", String.class);
        System.out.println(function2);
    }

    private static void method03() throws ClassNotFoundException, NoSuchMethodException {
        // Method getMethod(String name, Class<?>... parameterTypes) ：
        // 返回单个公共成员方法对象
        Class aClass = Class.forName("com.fanshe.demo05.Student");
        Method method = aClass.getMethod("function1");
        System.out.println(method);
    }

    private static void method02() throws ClassNotFoundException {
        // Method[] getDeclaredMethods()：
        // 返回所有成员方法对象的数组，不包括继承的
        Class aClass = Class.forName("com.fanshe.demo05.Student");
        Method[] declaredMethods = aClass.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);
        }
    }

    private static void method01() throws ClassNotFoundException {
        // Method[] getMethods()：返回所有公共成员方法对象的数组，包括继承的
        Class aClass = Class.forName("com.fanshe.demo05.Student");
        Method[] methods = aClass.getMethods();
        for (Method method : methods) {
            System.out.println(method);
        }
    }
}
